import datetime
import tkinter as tk
import json


def increase_score(current_score):
    # 创建一个 Tkinter 窗口
    root = tk.Tk()
    root.title("Scoreboard")

    # 创建一个标签用于显示分数
    score_label = tk.Label(root, text="Score: 0")
    score_label.pack()
    show_num = ""
    # 更新分数显示标签
    for i in current_score:
        show_num += (i + ":" + str(current_score[i]) + "\n")
    if show_num == "":
        score_label.config(text="暂无战绩")
    else:
        print(f"[{datetime.datetime.now()}] current_score")
        for i in current_score:
            print(f"    * [{i}] <:{current_score[i]}:>")
        print("#" * 50)
        score_label.config(text=show_num)
    root.mainloop()


"""# 创建一个按钮用于增加分数
score_button = tk.Button(root, text="Increase Score", command=increase_score)
score_button.pack()"""


def show():
    with open("core/json/current_score.json", "rb") as f:
        current_score = json.loads(f.read())["current_score"]

    increase_score(current_score)
    # 运行 Tkinter 事件循环


def end(current_score):
    with open("core/json/current_score.json", "rb") as f:
        data = json.loads(f.read())
    data["current_score"][str(datetime.datetime.now())] = current_score
    with open("core/json/current_score.json", "w") as f:
        bag = json.dumps(data)
        f.write(bag)


def clean():
    with open("core/json/current_score.json", "rb") as f:
        data = json.loads(f.read())
    data["current_score"] = {}
    with open("core/json/current_score.json", "w") as f:
        bag = json.dumps(data)
        f.write(bag)


